package com.greystripe.sdk;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.location.Location;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;

final class DeviceInfo
{
  private static Display b;
  private static int c;
  private static Location d;
  private static ArrayList e;
  private static DeviceInfo f;
  private Context a;

  private DeviceInfo()
  {
  }

  private DeviceInfo(Context paramContext)
  {
    this.a = paramContext;
    d = null;
  }

  protected static Location a()
  {
    return d;
  }

  private static String a(String paramString)
  {
    if (paramString == null)
      return null;
    try
    {
      String str = URLEncoder.encode(paramString, "UTF-8");
      return str;
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
    }
    return paramString;
  }

  private static String a(String paramString1, String paramString2)
  {
    if (paramString1 == null)
      paramString1 = "";
    try
    {
      byte[] arrayOfByte = MessageDigest.getInstance(paramString2).digest(paramString1.getBytes());
      BigInteger localBigInteger = new BigInteger(1, arrayOfByte);
      String str = String.format("%0" + (arrayOfByte.length << 1) + "x", new Object[] { localBigInteger });
      return str;
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      bd.e("Unable to generate device digest...", new Object[0]);
    }
    return "bad_id";
  }

  public static void addLocationListener(DeviceInfo.LocationListener paramLocationListener)
  {
    if (e == null)
      e = new ArrayList();
    e.add(new WeakReference(paramLocationListener));
  }

  private static DisplayMetrics c()
  {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    b.getMetrics(localDisplayMetrics);
    return localDisplayMetrics;
  }

  public static DeviceInfo getDeviceInfoController(Context paramContext)
  {
    try
    {
      if (f == null)
      {
        f = new DeviceInfo(paramContext);
        b = ((WindowManager)paramContext.getSystemService("window")).getDefaultDisplay();
        c = 0xF & paramContext.getResources().getConfiguration().screenLayout;
      }
      DeviceInfo localDeviceInfo = f;
      return localDeviceInfo;
    }
    finally
    {
    }
  }

  public static void updateLocation(Location paramLocation)
  {
    d = paramLocation;
    if (e != null)
    {
      Iterator localIterator = e.iterator();
      while (localIterator.hasNext())
      {
        WeakReference localWeakReference = (WeakReference)localIterator.next();
        if (localWeakReference != null)
        {
          DeviceInfo.LocationListener localLocationListener = (DeviceInfo.LocationListener)localWeakReference.get();
          if (localLocationListener != null)
            localLocationListener.onLocationUpdated(paramLocation);
        }
      }
    }
  }

  protected final String b()
  {
    try
    {
      String str = this.a.getPackageManager().getApplicationInfo(this.a.getPackageName(), 128).metaData.getString("gs_guid");
      return str;
    }
    catch (Exception localException)
    {
      bd.b("No application wide Greystripe GUID was found.", new Object[0]);
    }
    return null;
  }

  @JavascriptInterface
  public final String getAndroidVersion()
  {
    return a("Android-" + Build.VERSION.RELEASE);
  }

  @JavascriptInterface
  public final float getDensity()
  {
    return c().density;
  }

  @JavascriptInterface
  public final int getDensityDpi()
  {
    return c().densityDpi;
  }

  @JavascriptInterface
  public final String getGuid()
  {
    return bj.b();
  }

  @JavascriptInterface
  public final String getHashedAndroidId(String paramString)
  {
    return a(a(Settings.Secure.getString(this.a.getContentResolver(), "android_id")), paramString);
  }

  @JavascriptInterface
  public final String getHashedImeiId(String paramString)
  {
    if (paramString == null)
      return "$$GSHIID$$";
    if (paramString.startsWith("SHA-1"))
      return "$$GSHIID$$";
    return "$$GSMHIID$$";
  }

  @JavascriptInterface
  public final int getHeightPixels()
  {
    return c().heightPixels;
  }

  @JavascriptInterface
  public final String getLanguage()
  {
    return Locale.getDefault().getLanguage();
  }

  @JavascriptInterface
  public final int getOrientation()
  {
    return b.getOrientation();
  }

  @JavascriptInterface
  public final int getScreenSize()
  {
    return c;
  }

  @JavascriptInterface
  public final int getWidthPixels()
  {
    return c().widthPixels;
  }

  @JavascriptInterface
  public final boolean hasTelephony()
  {
    TelephonyManager localTelephonyManager = (TelephonyManager)this.a.getSystemService("phone");
    return (localTelephonyManager != null) && (localTelephonyManager.getPhoneType() != 0);
  }

  @JavascriptInterface
  public final boolean isTablet()
  {
    if ((11 <= Build.VERSION.SDK_INT) && (Build.VERSION.SDK_INT <= 13));
    while ((0xF & this.a.getResources().getConfiguration().screenLayout) >= 3)
      return true;
    return false;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.greystripe.sdk.DeviceInfo
 * JD-Core Version:    0.6.2
 */